/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function disp_confirm(messageText,yesUrl,noUrl)
{
    var r=confirm(messageText)
    if (r==true)
    {
        window.location = yesUrl;
    }
    else
    {
        window.location = noUrl;
    }
}
function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function MakeRequest(url,area)
{
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 1)
    {
      var content="<div align=\"center\"> <img src=\"img/loading.gif\"></div> ";
      HandleResponse(content,area);
    }
    if(xmlHttp.readyState == 4)
    {
      HandleResponse(xmlHttp.responseText,area);
    }
  }

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}

function HandleResponse(response,responseDiv)
{
  document.getElementById(responseDiv).innerHTML = response;
}

function openWindow(strUrl, strWindowName, strWindowFeatures){
    
    window.open(strUrl, strWindowName, strWindowFeatures)
}

function addCategory()
{
  var name= document.getElementById('catName').value;
  var main= document.getElementById('catMain').value;
  var url="./process/categoryAdd.php?name="+name+"&main="+main;
  MakeRequest(url,'info');
  MakeRequest("mainCategoryTable.php",'content');
}

function addSubCategory()
{
  var name= document.getElementById('catName').value;
  var main= document.getElementById('catMain').value;
  var url="./process/categoryAdd.php?name="+name+"&main="+main;
  MakeRequest(url,'info');
  var url2="subCategoryTable.php?id="+main;
  MakeRequest(url2,'content');
}

function updateCategory()
{
  var id= document.getElementById('catId').value;
  var name= document.getElementById('catName').value;
  var main= document.getElementById('catMain').value;

  var url="./process/categoryUpdate.php?id="+id+"&name="+name+"&main="+main;
  MakeRequest(url,'info');
  
  MakeRequest("mainCategoryTable.php",'content');
}

function updateSubCategory()
{
  var id= document.getElementById('catId').value;
  var name= document.getElementById('catName').value;
  var main= document.getElementById('catMain').value;

  var url="./process/subCategoryUpdate.php?id="+id+"&name="+name+"&main="+main;
  MakeRequest(url,'info');
  
  MakeRequest("subCategoryTable.php",'content');
}

function deleteCategory(url)
{
  MakeRequest(url,'info');
  MakeRequest("mainCategoryTable.php",'content');
}

function deleteSubCategory(id,main,url)
{
  var url=url+"?id="+id+"&main="+main;
  var url2="subCategoryTable.php?id="+main;
  MakeRequest(url,'info');
  MakeRequest(url2,'content');
}

function deleteProduct(id,cat,text){
  var r=confirm(text);
  var url="process/productDelete.php?id="+id;
  if(r == true){
      MakeRequest(url,'info');
      MakeRequest("productTable.php?cat="+cat,'content');
  }
}

function loadPage(){
  MakeRequest("mainCategoryTable.php",'content');  
}

function loadProductPage(){
  MakeRequest("productTable.php?cat=0",'content');
  
}



